package com.zhongjinkang.rhythm.AppView.Adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.zhongjinkang.rhythm.AppView.Activity.ImageDetailActivity
import com.zhongjinkang.rhythm.R

import com.zhongjinkang.rhythm.databinding.AdapterItemBinding
import com.zhongjinkang.rhythm.databinding.AdapterItemPeopleListBinding
import com.zhongjinkang.rhythm.uiBean.PortrayBean

class PeopleDetailAdapter(private val myContext: Context, var list: List<PortrayBean>) :
    RecyclerView.Adapter<PeopleDetailAdapter.ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return ViewHolder(AdapterItemPeopleListBinding.inflate(LayoutInflater.from(myContext),parent,false))
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.setData(list[position])
    }


    inner class ViewHolder(private val viewBinding: AdapterItemPeopleListBinding) :
        RecyclerView.ViewHolder(viewBinding.root) {

        init {
            viewBinding.iv.setOnClickListener {
                val intent = Intent(myContext, ImageDetailActivity::class.java)
                intent.putExtra("peopleId", list[layoutPosition].peopleId)
                intent.putExtra("url", list[layoutPosition].url)
                myContext.startActivity(intent)
            }
        }

        fun setData(portrayBean: PortrayBean) {

            Glide.with(myContext).load(portrayBean.url)
                .placeholder(R.mipmap.ic_launcher_round)
                .into(viewBinding.iv);
        }

    }

}